package terra;

import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;

public final class Config
{
	public static int DATABASE_MAX_CONNECTIONS = 50;
	public static int DATABASE_MAX_IDLE_TIME = 2000;
	public static String DATABASE_DRIVER = "com.mysql.jdbc.Driver";
	public static String DATABASE_URL = "jdbc:mysql://localhost/infinite";
	public static String DATABASE_LOGIN = "root";
	public static String DATABASE_PASSWORD = "root";
	public static long DATABASE_CONNECTION_TIMEOUT = 200000;
	public static int DATABASE_PARTITION_COUNT = 5;
	public static long DATABASE_TIMEOUT = 1000;

	
	public static int GAMEPORT = 9088;
	public static String SERVERHOSTNAME = "localhost";
	public static boolean debug = false;
	public static boolean logInFile = false;
	public static boolean freeMove = false;
	public static int MAX_CHANCE = 100000;
	/** Настройки воды*/
	public static float MaxMass = 1.0f; // 1.0f The normal, un-pressurized mass of a full water cell
	public static float MaxCompress = 0.01f; // 0.02f How much excess water a cell can store, compared to the cell above it
	public static float MinMass = 0.0001f;  // 0.0001f Ignore cells that are almost dry
	public static float MaxSpeed = 0.1f;   // 0.05f max units of water moved out of one block to another, per timeste
	public static float MinFlow = 0.001f;	// 0.001f 

	/** Настройки карт*/
	
	public static int mapWidth;
	public static int mapHeight;
	public static long mapSaveDelay = 0;
	/** Начальное количество карт, если указать 3 - то карт сгенерируется 6 (слева и справа по 3 от игрока).*/
	public static int initialSize = 10;
	/** Дополнительное количество тайлов в актуальной карте (для отрисовки и обновления).
	 * Указанное количество добавляется по половине слева и справа*/
	public static int actualMapSizeAdd = 8;
	/** Расстояние до границы карт для подгрузки\создания карты.*/
	public static int distanceForLoad = 5;
	/** Расстояние до границы карт для сохранения и удаления карты. */
	public static int distanceForSave = 10;
	/** Размер одного тайла (блока).*/
	public static int tileSize = 24;
	public static int tileCountForBiomMixing = 8;
	public static boolean saveGeneratedMapImages = true;
	public static boolean saveGeneratedMapImagesFull = false;
	
	/** количество симуляций при начале игры */
	public static int waterSimulationTime = 50;
	
	/** Настройки гравитации*/
	public static float gravity = 16f;
	public static float maxItemGravity = 16f;
	public static float maxGravity = 32f;
	public static float waterGravity = 6f;
	
	public static float itemDropRate = 1;
	
	public static boolean disableLighting = true;
	
	/** Настройки менеджера смены дня\ночи*/
	public static float dayLight = 1f;
	public static float nightLight = 0.2f;
	public static float duskLight = 0.4f;	
	public static float dawnLight = 0.4f;	
	public static long dayTime = 120*1000L;
	public static long nightTime = 30*1000L;
	public static long duskTime = 10*1000L;
	public static long dawnTime = 10*1000L;
	public static boolean autoPickup = false;
	
	public static void loadConfig()	{
		Properties prop = new Properties();
		try {
			File f = new File("data" + File.separatorChar + "config.ini");
			if (f.exists())
				prop.load(new FileInputStream(f));
			else
				prop.load(Config.class.getResourceAsStream("config.ini"));
		} catch (Exception e){
			e.printStackTrace();
		}
		/*
		 *
	public static long DATABASE_CONNECTION_TIMEOUT = 200000;
	public static long DATABASE_TIMEOUT = 1000;
		 */
		DATABASE_MAX_CONNECTIONS = Integer.parseInt(prop.getProperty("dbMaxConnections", "50"));
		DATABASE_MAX_IDLE_TIME = Integer.parseInt(prop.getProperty("dbMaxIdleTime", "2000"));
		DATABASE_DRIVER = prop.getProperty("dbDriver", "com.mysql.jdbc.Driver");
		DATABASE_URL = prop.getProperty("dbURL", "jdbc:mysql://localhost/infinite");
		DATABASE_LOGIN = prop.getProperty("dbLogin", "root");
		DATABASE_PASSWORD = prop.getProperty("dbPass", "root");
		DATABASE_TIMEOUT = Integer.parseInt(prop.getProperty("dbTimeout", "1000"));
		DATABASE_CONNECTION_TIMEOUT = Integer.parseInt(prop.getProperty("dbConnectionTimeout", "200000"));
		
		
		GAMEPORT =  Integer.parseInt(prop.getProperty("port", "9088"));
		SERVERHOSTNAME = prop.getProperty("hostName", "localhost");
		dayLight = Float.parseFloat(prop.getProperty("dayLight", "1.0f"));
		nightLight = Float.parseFloat(prop.getProperty("nightLight", "0.2f"));
		duskLight = Float.parseFloat(prop.getProperty("duskLight", "0.5f"));
		dawnLight = Float.parseFloat(prop.getProperty("dawnLight", "0.4f"));
		
		dayTime = Integer.parseInt(prop.getProperty("dayTime", "120"))*1000L;
		nightTime = Integer.parseInt(prop.getProperty("nightTime", "30"))*1000L;
		duskTime = Integer.parseInt(prop.getProperty("duskTime", "10"))*1000L;
		dawnTime = Integer.parseInt(prop.getProperty("dawnTime", "10"))*1000L;
		
		autoPickup = Boolean.parseBoolean(prop.getProperty("autoPickup", "false"));
		debug = Boolean.parseBoolean(prop.getProperty("debug", "false"));
		freeMove = Boolean.parseBoolean(prop.getProperty("freeMove", "false"));
		disableLighting = Boolean.parseBoolean(prop.getProperty("disableLighting", "true"));
		
		MaxMass = Float.parseFloat(prop.getProperty("waterMaxMass", "1.0f"));
		MinMass = Float.parseFloat(prop.getProperty("waterMinMass", "0.0001f"));
		MaxCompress = Float.parseFloat(prop.getProperty("waterMaxCompress", "0.01f"));
		MaxSpeed = Float.parseFloat(prop.getProperty("waterMaxSpeed", "0.1f"));
		MinFlow = Float.parseFloat(prop.getProperty("waterMinFlow", "0.001f"));

		mapWidth = Integer.parseInt(prop.getProperty("mapWidth", "64"));
		mapHeight = Integer.parseInt(prop.getProperty("mapHeight", "512"));
		mapSaveDelay = Integer.parseInt(prop.getProperty("mapSaveDelay", "600000"));

		initialSize = Integer.parseInt(prop.getProperty("mapInitialSize", "10"));
		actualMapSizeAdd = Integer.parseInt(prop.getProperty("actualMapSizeAdd", "8"));
		distanceForLoad = Integer.parseInt(prop.getProperty("distanceForLoad", "4"));
		distanceForSave = Integer.parseInt(prop.getProperty("distanceForSave", "8"));

		tileSize = Integer.parseInt(prop.getProperty("tileSize", "16"));
		tileCountForBiomMixing = Integer.parseInt(prop.getProperty("tileCountForBiomMixing", "8"));
		saveGeneratedMapImages = Boolean.parseBoolean(prop.getProperty("saveGeneratedMapImages", "true"));
		saveGeneratedMapImagesFull = Boolean.parseBoolean(prop.getProperty("saveGeneratedMapImagesFull", "false"));
		
		waterSimulationTime = Integer.parseInt(prop.getProperty("waterSimulationTime", "30"));		
		gravity = Float.parseFloat(prop.getProperty("gravity", "16f"));
		waterGravity = Float.parseFloat(prop.getProperty("waterGravity", "6f"));
		maxGravity = Float.parseFloat(prop.getProperty("maxGravity", "32f"));
		maxItemGravity = Float.parseFloat(prop.getProperty("maxItemGravity", "8f"));
		
		itemDropRate = Float.parseFloat(prop.getProperty("itemDropRate", "1f"));
		logInFile = true;
	}
}
